package com.fs.cv.utils;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description:
 * @author: XianHua Zhou
 * @createDate: 2020/9/28
 * @version: 1.0
 */
@WebServlet("/code")
public class GetCapct extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //通过工具类生成验证码，再将验证码封装到circlecaptcha对象
        CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(110,30,4,2);
        //配置输出流，把验证码输出到页面
        ServletOutputStream outputStream = resp.getOutputStream();
        //获取验证码信息
        String code = captcha.getCode();
        req.getSession().setAttribute("rightCod",code);
        //将验证码写入到页面
        captcha.write(outputStream);
        outputStream.flush();
        outputStream.close();

    }
}
